package com.sh.data.engine.repository.dao.integration.datasource.entity;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sh.data.engine.repository.dao.base.EngineBaseModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.Date;

/**
 * @author: mengzheng.mhc
 * @date: 2024/5/29 15:50
 */
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@Data
@TableName("tb_datasource")
public class DataSourceEntity extends EngineBaseModel<DataSourceEntity> {

    private String dsName;
    private String dsType;
    private String dsLink;
    private String dsDesc;
    private Integer status;
    private Long projectId;
    private Date lastUpdate;
    private String connectionProperty;
    private Integer isSystem;
    private String rdbmsConfigInfo;
    private String hiveConfigInfo;
    private String maxComputeConfigInfo;
    private String mongoConfigInfo;
    private String hdfsConfigInfo;

    @TableLogic(value = "1", delval = "0")
    private Integer rowState;

    @TableField(exist = false)
    private RdbmsConfig rdbmsConfig;

    @TableField(exist = false)
    private HiveConfig hiveConfig;

    @TableField(exist = false)
    private MaxComputeConfig maxComputeConfig;

    @TableField(exist = false)
    private MongoConfig mongoConfig;

    @TableField(exist = false)
    private HDFSConfig hdfsConfig;

    public RdbmsConfig getRdbmsConfig() {
        return JSON.parseObject(rdbmsConfigInfo, RdbmsConfig.class);
    }

    public void setRdbmsConfig(RdbmsConfig rdbmsConfig) {
        this.rdbmsConfig = rdbmsConfig;
        this.rdbmsConfigInfo = JSON.toJSONString(rdbmsConfig);
    }

    public HiveConfig getHiveConfig() {
        return JSON.parseObject(hiveConfigInfo, HiveConfig.class);
    }

    public void setHiveConfig(HiveConfig hiveConfig) {
        this.hiveConfig = hiveConfig;
        this.hiveConfigInfo = JSON.toJSONString(hiveConfig);
    }

    public MaxComputeConfig getMaxComputeConfig() {
        return JSON.parseObject(maxComputeConfigInfo, MaxComputeConfig.class);
    }

    public void setMaxComputeConfig(MaxComputeConfig maxComputeConfig) {
        this.maxComputeConfig = maxComputeConfig;
        this.maxComputeConfigInfo = JSON.toJSONString(maxComputeConfig);
    }

    public MongoConfig getMongoConfig() {
        return JSON.parseObject(mongoConfigInfo, MongoConfig.class);
    }

    public void setMongoConfig(MongoConfig mongoConfig) {
        this.mongoConfig = mongoConfig;
        this.mongoConfigInfo = JSON.toJSONString(mongoConfig);
    }

    public HDFSConfig getHdfsConfig() {
        return JSON.parseObject(hdfsConfigInfo, HDFSConfig.class);
    }

    public void setHdfsConfig(HDFSConfig hdfsConfig) {
        this.hdfsConfig = hdfsConfig;
        this.hdfsConfigInfo = JSON.toJSONString(hdfsConfig);
    }

    @Data
    public static class RdbmsConfig {
        private String dbName;
        private Integer port;
        private String username;
        private String password;
        private String server;
        private String version;
        private Integer oracleConnectionType;
        private String schema;
    }

    @Data
    public static class HiveConfig {
        private String dbName;
        private Integer port;
        private String username;
        private String password;
        private String server;
        private String version;
        private String hiveSiteAddress;
        private String originalFilename;
    }

    @Data
    public static class MongoConfig {

        private String port;

        private String server;

        private String dbName;

        private String username;

        private String password;

        private String authDbName;
    }

    @Data
    public static class HDFSConfig {

        /**
         * hdfs的用户
         */
        private String hdfsUser;

        private String server;

        private Integer port;
    }

    @Data
    public static class MaxComputeConfig {
        private String accessId;

        /**
         * accessKey
         */
        private String accessKey;

        /**
         * 项目
         */
        private String project;

        /**
         * endPoint
         */
        private String endPoint;

        /**
         * endPoint
         */
        private String tunnelEndPoint;
    }
}
